package com.party.admin.web.interceptor;

import com.party.admin.redisPubSub.subscribe.SubScribeMessage;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * @Description: spring容器初始化完成后自动执行的类
 * @Author: yangshoukun
 * @Date: 2018/4/2 14:40
 */
@Component
public class TXZApplicationListener implements ApplicationListener<ContextRefreshedEvent> {

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        // spring容器可以有多个ApplicationContext，例如spring MVC就存在一个ApplicationContext，但是根ApplicationContext却只有一个
        if(event.getApplicationContext().getParent() == null ) {
            ApplicationContext applicationContext = event.getApplicationContext();
            SubScribeMessage subScribeMessage = applicationContext.getBean("subScribeMessage", SubScribeMessage.class);
            subScribeMessage.subscribeChannel(SubScribeMessage.CHANNEL_NAME);
            subScribeMessage.subscribeChannel(SubScribeMessage.COMPETITION_IMPORT_CHANNEL_NAME);
            subScribeMessage.subscribeChannel(SubScribeMessage.CROWDFUND_EXPORT_CHANNEL_NAME);
        }
    }
}

